package org.jaaksi.commondemo.gson;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import java.lang.annotation.Annotation;
import java.util.Collection;

/**
 * @author fuchaoyang
 */
public class IgnoreStrategy implements ExclusionStrategy {

  /**
   * @see ExclusionStrategy#shouldSkipClass (java.lang.Class)
   */
  @Override public boolean shouldSkipClass(Class<?> clazz) {
    return false;
  }

  /**
   * /**
   *
   * @return 是否忽略字段
   * @see ExclusionStrategy#shouldSkipField (com.google.gson.
   * FieldAttributes)
   */
  @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) {
    Collection<Annotation> annotations = fieldAttributes.getAnnotations();
    for (Annotation annotation : annotations) {
      if (annotation.annotationType() == Ignore.class) {
        Ignore ignore = (Ignore) annotation;
        if (ignore.ignoreParse()) return true;
      }
    }
    return false;
  }
}  